<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改首页活动信息')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-JiajiaHomeActivity-edit" th:object="${jiajiaHomeActivity}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8">
                <input id="file" accept="image/jpg,image/jpeg,image/png" name="file"  class="form-control"  type="file">
                <img style="width: 80px ;height: auto;" th:src="*{url}" id="imgPhoto"  />
                <input th:field="*{url}" style="display: none" id="url" name="url" class="form-control"   type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型0招聘1活动：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b">
                    <option value="" th:selected="${jiajiaHomeActivity.type}==null">请选择类型</option>
                    <option value="0" th:selected="${jiajiaHomeActivity.type} == 0">招聘</option>
                    <option value="1" th:selected="${jiajiaHomeActivity.type}">活动</option>
                </select>
<!--                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "jiajia/JiajiaHomeActivity";
    $("#form-JiajiaHomeActivity-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-JiajiaHomeActivity-edit').serialize());
        }
    }
    $("#file").bind('change', function () {
        $("#imgPhoto").show();
        $("#imgPhoto").attr("src",URL.createObjectURL($(this)[0].files[0]));

        uploadFile("#file",function (result) {
            $("#url").val(result.url);
        })
    });

    function uploadFile(idSelector,callback) {
        var formData = new FormData();
        formData.append('file',$(idSelector)[0].files[0]);
        $.ajax({
            url: "/common/admin/upload/up/single",
            data: formData,
            type: "post",
            dataType: "json",
            processData: false,
            contentType: false,
            success: function(result) {
                callback(result)
            }
        })
    }

    $(function () {
        $('.summernote').each(function (i) {
            $('#' + this.id).summernote({
                lang: 'zh-CN',
                dialogsInBody: true,
                callbacks: {
                    onChange: function (contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function (files) {
                        var obj = this;
                        var data = new FormData();
                        data.append("file", files[0]);
                        $.ajax({
                            type: "post",
                            url: "/common/admin/upload/up/single",
                            data: data,
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'json',
                            success: function (result) {
                                if (result.code == web_status.SUCCESS) {
                                    $('#' + obj.id).summernote('insertImage', result.url);
                                } else {
                                    $.modal.alertError(result.msg);
                                }
                            },
                            error: function (error) {
                                $.modal.alertWarning("图片上传失败。");
                            }
                        });
                    }
                }
            });
            var content = $("input[name='" + this.id + "']").val();
            $('#' + this.id).summernote('code', content);
        })
    });

    // $(".file-upload").each(function (i) {
    //     var val = $("input[name='" + this.id + "']").val()
    //     $(this).fileinput({
    //         url: '/common/admin/upload/up/single',
    //         initialPreviewAsData: true,
    //         initialPreview: [val],
    //         maxFileCount: 1,
    //         autoReplace: true
    //     }).on('fileuploaded', function (event, data, previewId, index) {
    //         $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    //     }).on('fileremoved', function (event, id, index) {
    //         $("input[name='" + event.currentTarget.id + "']").val('')
    //     })
    //     $(this).fileinput('_initFileActions');
    // });
</script>
</body>
</html>